######################################
# 主窗体
######################################

import sys

from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QBrush, QPixmap, QIcon
from PyQt5.QtWidgets import *

from WindowCropByShp import WindowCropByShp
from WindowCropByGrid import WindowCropByGrid

myWindow = None


# 子窗口关闭事件监听：显示主窗口
def childWindowCloseEvt():
    myWindow.show()


class MyWindow(QtWidgets.QDialog):
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        self.calWindow = None
        self.extWindow = None
        self.setObjectName("MyWindow")
        self.resize(641, 361)
        self.setWindowTitle("遥感影像深度学习样本批量裁剪软件")
        self.setWindowIcon(QIcon("./images/setup.png"))
        window_pale = QPalette()
        window_pale.setBrush(self.backgroundRole(), QBrush(QPixmap("./images/bg.png")))
        self.setPalette(window_pale)
        # Qt.WindowMaximizeButtonHint |
        self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowMinimizeButtonHint | Qt.WindowCloseButtonHint)
        
        self.pushButton_grid = QtWidgets.QPushButton(parent=self)
        self.pushButton_grid.setGeometry(QtCore.QRect(150, 150, 150, 35))
        self.pushButton_grid.setObjectName("pushButton_grid")
        self.pushButton_grid.setText("规则格网裁剪")
        self.pushButton_grid.clicked.connect(self.showWindowGrid)

        self.pushButton_shp = QtWidgets.QPushButton(parent=self)
        self.pushButton_shp.setGeometry(QtCore.QRect(350, 150, 150, 34))
        self.pushButton_shp.setObjectName("pushButton_shp")
        self.pushButton_shp.setText("Shp图形裁剪")
        self.pushButton_shp.clicked.connect(self.showWindowShp)

        # self.pushButton_convert = QtWidgets.QPushButton(parent=self)
        # self.pushButton_convert.setGeometry(QtCore.QRect(450, 150, 150, 34))
        # self.pushButton_convert.setObjectName("pushButton_convert")
        # self.pushButton_convert.setText("格式转换")
        # self.pushButton_convert.clicked.connect(self.showWindowShp)

    def showWindowGrid(self):
        self.extWindow = WindowCropByGrid()
        self.extWindow.closeEvtSig.connect(childWindowCloseEvt)
        self.extWindow.show()
        myWindow.hide()

    def showWindowShp(self):
        self.calWindow = WindowCropByShp()
        self.calWindow.closeEvtSig.connect(childWindowCloseEvt)
        self.calWindow.show()
        myWindow.hide()

    def warm(self, msg):
        QMessageBox.warning(self, "警告", msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)

    def info(self, msg):
        QMessageBox.information(self, "警告", msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    myWindow = MyWindow()
    myWindow.show()
    sys.exit(app.exec_())
